import { Zoom, Fullscreen, MouseLocation, MapTheme, LayerSwitch, Scale, Logo } from '@antv/l7';

export default function useControl(scene, map) {
  const sceneControl = {};

  sceneControl.zoom = new Zoom({
    position: 'topleft',
  });

  sceneControl.fullscreen = new Fullscreen();

  sceneControl.mouseLocation = new MouseLocation({
    position: 'bottomright',
  });

  sceneControl.logo = new Logo({
    href: 'http://www.x-zd.com',
    img: 'http://www.x-zd.com/themes/simpleboot3_web/public/web/images/image/logo_03.png',
  });

  sceneControl.scale = new Scale({
    position: 'bottomright',
  });

  //添加主题切换控件
  sceneControl.mapTheme = new MapTheme({
    options: [
      {
        text: '白天导航地图',
        value: 'mapbox://styles/mapbox/navigation-day-v1',
        img: '/themes/navigation-day-v1.png',
      },
      {
        text: '夜间导航地图',
        value: 'mapbox://styles/mapbox/navigation-night-v1',
        img: '/themes/navigation-night-v1.png',
      },
      {
        text: '标记卫星地图',
        value: 'mapbox://styles/mapbox/satellite-streets-v12',
        img: '/themes/satellite-streets-v12.png',
      },
      {
        text: '普通卫星地图',
        value: 'mapbox://styles/mapbox/satellite-v9',
        img: '/themes/satellite-v9.png',
      },
    ],
  });

  for (let key in sceneControl) {
    scene.addControl(sceneControl[key]);
  }

  sceneControl['scale'].hide();
  map.on('zoom', function () {
    let zoom = map.getZoom();
    if (zoom < 5) {
      sceneControl.scale.hide();
    } else {
      sceneControl.scale.show();
    }
  });
}
